package com.jr.controller;

import com.jr.entry.BlogText;
import com.jr.service.BlogTextService;
import com.jr.util.ResultObject;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController /*替换@RestController=@Controller + @ResponseBody*/
@RequestMapping("/Blog/")
public class BlogTextController {
    @Autowired
    private BlogTextService blogTextMapperService;
    @Autowired
    private ResultObject result;
    @Autowired
    private BlogText blogText;

    @RequestMapping("selectByUid")
    public ResultObject selectByUid(BlogText blogText){
        result.setResult(blogTextMapperService.selectByUid(blogText));
        return result;
    }

    @RequestMapping("updateBlogTextById")
    public ResultObject updateBlogTextById(BlogText blogText){
        result.setResult(blogTextMapperService.updateBlogTextByBlogId(blogText));
        return result;
    }

    @RequestMapping("selectByBlogid")
    public ArrayList<BlogText> selectByBlogid(BlogText blogText){
        ArrayList<BlogText> blogTexts = blogTextMapperService.selectByBlogid(blogText);
        System.out.println(blogTextMapperService.selectByBlogid(blogText));
        return blogTexts;
    }


    @RequestMapping("showAll")
    public ResultObject showALl(Integer pageNumber){
        result.setStatus(400);
        int b=3;
        result.setResult(blogTextMapperService.showAllBlogText(pageNumber,b));
        return result;
    }
    @RequestMapping("getNumber")
    public Integer getNumber(){
        return blogTextMapperService.getNumber();
    }

    @RequestMapping("showJava")
    public ResultObject showByType(BlogText blogText){
        result.setStatus(400);
        System.out.println(blogText.getType());
        result.setResult(blogTextMapperService.showBlogTextByType(blogText));
        return result;
    }
    @RequestMapping("updateClickNumber")
    public ResultObject updateClickNumber(Integer blogid){
        if (blogid!=null){
            result.setStatus(blogid);
            result.setResult(blogTextMapperService.changeClickNumber(blogid));
        }
        return result;
    }

    @RequestMapping("showByClickNumber")
    public ResultObject showByClickNumber(){
        result.setResult(blogTextMapperService.showBlogTextByClickNumber());
        return result;
    }

    @RequestMapping("showByTypeAndClickNumber")
    public ResultObject showByTypeAndClickNumber(String type){
        blogText.setType(type);
        result.setResult(blogTextMapperService.showSuggest(blogText));
        return result;
    }

    @RequestMapping("showBlogText")
    public ResultObject showBlogText(Integer blogid){
        blogText.setBlogid(blogid);
        result.setStatus(blogid);
        result.setResult(blogTextMapperService.showBlogTextDetail(blogText));
        return result;
    }
    /*盛志健*/
    /*盛的删除方法*/
    @RequestMapping("deleteBlogTextByBlogId")
    public ResultObject deleteBlogTextByBlogId(BlogText blogText){
        result.setResult(blogTextMapperService.deleteBlogTextByBlogId(blogText));
        return result;
    }
    /*置顶*/
    @RequestMapping("showBlogTextByClickNumber")
    public ArrayList<BlogText> showBlogTextByClickNumber(){
        ArrayList<BlogText> blogTextArrayList = blogTextMapperService.showBlogTextByClickNumber();
        return blogTextArrayList;
    }

    @RequestMapping("showBlogTextDetail")
    public ResultObject showBlogTextDetail(BlogText blogText){
        result.setStatus(400);
        result.setResult(blogTextMapperService.showBlogTextDetail(blogText));
        return result;
    }
    @RequestMapping("insertBlog")
    public ResultObject insertBlog(BlogText blogText) {
        result.setStatus(400);
        if (blogText.getDetail()!=""){
            result.setMess("添加成功");
            System.out.println(result.getMess());
            result.setResult(blogTextMapperService.addBlogText(blogText));
        }else {
            result.setMess("添加失败");
        }
        return result;
    }

    @RequestMapping("showByStatus")
    public  ResultObject showByStatus(Integer status){
        System.out.println(status);
        ArrayList<BlogText> blogTexts=blogTextMapperService.selectByStatus(status);
        result.setResult(blogTexts);
        System.out.println(result.getResult());
        return result;
    }


}
